<?php

// Need no url for graphviz cuz site is offline
Class GraphViz{
	// visit site: http://urlgreyhot.com/graphviz/
	function site_to_GraphViz(){
		$pdo = new DB_Pdo('vandersanden'); // new pdo object
		$result = $pdo->prepare('select id,url,links,name,parsed from crawler');
		$result->execute();
		$pagesarray = $result->fetchAll(PDO::FETCH_ASSOC);
		$page = "0\t0\tRoot\n";
		foreach ($pagesarray as $pageinfo){
		$page .= $pageinfo['id']."\t".$pageinfo['url']."\t".$pageinfo['name']."\t".$pageinfo['url']."\n";
		}
		echo $page;
		$pdo = null;
		$result = null;
	}

        function determine_name($link){
		/* rename function to prevent duplicate entrys in the database*/
		$basename = basename($link);
		//echo "basename: ".$basename;
		if ($basename=="index.php" or $basename =="index.asp" or $basename =="index.html" or $basename=="index.htm"){
			$dirarray = explode("/",$link);
			$lastitem = count($dirarray)-2;
			$returnname = $dirarray[$lastitem];
		}
		else{$returnname = $basename;}
		//echo " returnname: ".$returnname."\n";
		return $returnname;
	}

}
?>
